package com.ling.dao;

import com.ling.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

public interface UserMapper {

    //根据ID查询用户
    @Select("select id,name,pwd as password from User where id=#{userId}")
    User getUserById(@Param("userId") int id);

    //    注解查询全部用户
    @Select("select id,name,pwd as password from User")
    List<User> getUsers();

    //添加用户
    @Insert("insert into User(id,name,pwd) values (#{id},#{name},#{password})")
    int addUser(User user);

    //修改用户
    @Update("update User set name=#{name},pwd=#{password} where id=#{id}")
    int updataUser(User user);

    //删除用户
    /*  #{} 的作用主要是替换预编译语句(PrepareStatement)中的占位符? 【推荐使用】
    *   ${} 的作用是直接进行字符串替换【可能会产生SQL注入  */
    @Delete("delete from User where id=#{userId}")
    int deleteUser(@Param("userId") int id);
}
